package com.magicborrow.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.magicborrow.R;
import com.magicborrow.activity.LonginActivity;
import com.magicborrow.activity.PushStuffActivity;
import com.magicborrow.adapter.SearchEmptyAdapter;
import com.magicborrow.utils.UserTools;

import java.util.ArrayList;

/**
 * Created by River on 5/15/16.
 */
public class SearchEmptyFragment extends Fragment{

    private RelativeLayout mFragmentLayout;
    private RecyclerView mRecyclerView;
    private ArrayList mData;
    private SearchEmptyAdapter mSearchEmptyAdapter;
    private TextView publish;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mFragmentLayout = (RelativeLayout)inflater.inflate(R.layout.search_empty,null);
        initView();
        initListener();
        initData();
        return mFragmentLayout;
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    private void initView(){
        publish = (TextView)mFragmentLayout.findViewById(R.id.publish);
        mRecyclerView = (RecyclerView)mFragmentLayout.findViewById(R.id.recyclerView);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
        linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        mRecyclerView.setLayoutManager(linearLayoutManager);
    }

    private void initData(){
        mData = new ArrayList<>();
        mData.add("");
        mData.add("");
        mData.add("");
        mData.add("");
        mData.add("");
        mData.add("");
        mData.add("");
        mData.add("");
        mData.add("");
        mData.add("");
        mData.add("");
        mData.add("");
        mData.add("");
        mData.add("");
        mSearchEmptyAdapter = new SearchEmptyAdapter(mData);
        mRecyclerView.setAdapter(mSearchEmptyAdapter);
    }

    private void initListener(){
        publish.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                if(UserTools.getUser(SearchEmptyFragment.this.getActivity()) == null){
                    intent.setClass(SearchEmptyFragment.this.getActivity(),LonginActivity.class);
                }else{
                    intent.setClass(SearchEmptyFragment.this.getActivity(),PushStuffActivity.class);
                }
                startActivity(intent);
            }
        });
    }

}
